<?php

namespace services;
require_once "../vendor/alibabacloud/imm-20170906/autoload.php";
use AlibabaCloud\SDK\Imm\V20170906\Imm;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Imm\V20170906\Models\GetOfficePreviewURLRequest;
use AlibabaCloud\SDK\Imm\V20170906\Models\RefreshOfficePreviewTokenRequest;
class ImmService{
   const accessKeyId="LTAI5tEgpRqSq1Gzoaem3MBh";
   const accessKeySecret="S6Aebk3yCzJ28GiGkeiG0Y3vQ04Epf";
   //const endpoint="oss-cn-hangzhou.aliyuncs.com";
   //const bucket = "jjzsy";
   const endpoint="imm.cn-hangzhou.aliyuncs.com";
   const bucket = "gear-educ";
   public $options = null;
   public function __construct(){
       $this->options = array();
       //$this->options["proxy_url"]="http://username:password@hostname:8080";
   }

    /**
     * 使用AK&SK初始化账号Client
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Imm Client
     */
    public static function createClient(){
        $config = new Config([
            // 您的AccessKey ID
            "accessKeyId" => self::accessKeyId,
            // 您的AccessKey Secret
            "accessKeySecret" => self::accessKeySecret
        ]);
        // 访问的域名
        $config->endpoint = self::endpoint;
        return new Imm($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args){
        $client = self::createClient();
        $getOfficePreviewURLRequest = new GetOfficePreviewURLRequest([
            "project" => "cljy",
            "srcUri" => "oss://gear-educ/cljy/".$args,
            "srcType" => pathinfo($args,PATHINFO_EXTENSION)
        ]);
        // 复制代码运行请自行打印 API 的返回值
        return $client->getOfficePreviewURL($getOfficePreviewURLRequest);
    }


    public static function main2($args){
        $client = self::createClient();
        $refreshOfficePreviewTokenRequest = new RefreshOfficePreviewTokenRequest([
            "project" => "cljy",
            "accessToken" => $args['accessToken'],
            "refreshToken" => $args['refreshToken']
        ]);
        // 复制代码运行请自行打印 API 的返回值
        return $client->refreshOfficePreviewToken($refreshOfficePreviewTokenRequest);
    }

}
